﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.SqlClient;
using EShop.Common;

namespace EShop.DAL
{
    public class MerchandiseBindDAL:BaseDAL
    {
        public int MerchandiseBindAppend(string BindName, int MerchandiseUnitID, decimal SellPrice)
        {
            string strUSP = "USP_MerchandiseBind_Append";
            try
            {
                SqlParameter[] parameters ={
                                            new SqlParameter("@BindName",SqlDbType.VarChar,255),
                                            new SqlParameter("@MerchandiseUintID",SqlDbType.Int),
                                            new SqlParameter("@SellPrice",SqlDbType.Decimal)
                                        };
                parameters[0].Value = BindName;
                parameters[1].Value = MerchandiseUnitID;
                parameters[2].Value = SellPrice;

                return DbHelper.ExecuteNonQuerySQL(strUSP, CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                log.Write(string.Format("USP:{0}\r\nError:{1}", strUSP, ex.Message));
                throw;
            }
        }

        public int MerchandiseBindDetailAppend(string BindID,string Barcode, int Quantity)
        {
            string strUSP = "USP_MerchandiseBindDetailAppend";
            try
            {
                SqlParameter[] parameters ={
                                               new SqlParameter("@BindID",SqlDbType.VarChar,9),
                                            new SqlParameter("@Barcode",SqlDbType.VarChar,30),
                                            new SqlParameter("@Quantity",SqlDbType.Int)
                                           };
                parameters[0].Value = BindID;
                parameters[1].Value = Barcode;
                parameters[2].Value = Quantity;
                return DbHelper.ExecuteNonQuerySQL(strUSP, CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                log.Write(string.Format("USP:{0}\r\nError:{1}", strUSP, ex.Message));
                throw;
            }
        }

        public DataTable MerchandiseBindQuery(string BindID)
        {
            string strUSP = "USP_MerchandiseBind_Query";
            try
            {
                SqlParameter[] parameters ={
                                            new SqlParameter("@BindID",SqlDbType.VarChar,9)
                                        };
                parameters[0].Value = BindID;
                return DbHelper.ExecuteDataSetSQL(strUSP, CommandType.StoredProcedure, parameters).Tables[0];
            }
            catch (Exception ex)
            {
                log.Write(string.Format("USP:{0}\r\nError:{1}", strUSP, ex.Message));
                throw;
            }
        }

        public DataTable MerchandiseBindDetailQuery(string BindID, string Barcode)
        {
            string strUSP = "USP_MerchandiseBindDetail_Query";
            try
            {
                SqlParameter[] parameters ={
                                            new SqlParameter("@BindID",SqlDbType.VarChar,9),
                                            new SqlParameter("@Barcode",SqlDbType.VarChar,30)
                                        };
                parameters[0].Value = BindID;
                parameters[1].Value = Barcode;
                return DbHelper.ExecuteDataSetSQL(strUSP, CommandType.StoredProcedure, parameters).Tables[0];
            }
            catch (Exception ex)
            {
                log.Write(string.Format("USP:{0}\r\nError:{1}", strUSP, ex.Message));
                throw;
            }
        }

        public int MerchandiseBindDelete(string BindID)
        {
            string strUSP = "USP_MerchandiseBind_Delete";
            try
            {
                SqlParameter[] parameters ={
                                            new SqlParameter("@BindID",SqlDbType.VarChar,9)
                                        };
                parameters[0].Value = BindID;

                return DbHelper.ExecuteNonQuerySQL(strUSP, CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                log.Write(string.Format("USP:{0}\r\nError:{1}", strUSP, ex.Message));
                throw;
            }
        }

        public int MerchandiseBindDetailDelete(string BindID, string Barcode)
        {
            string strUSP = "USP_MerchandiseBindDetail_Delete";
            try
            {
                SqlParameter[] parameters ={
                                            new SqlParameter("@BindID",SqlDbType.VarChar,9),
                                            new SqlParameter("@Barcode",SqlDbType.VarChar,30)
                                        };
                parameters[0].Value = BindID;
                parameters[1].Value = Barcode;

                return DbHelper.ExecuteNonQuerySQL(strUSP, CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                log.Write(string.Format("USP:{0}\r\nError:{1}", strUSP, ex.Message));
                throw;
            }
        }

        public int MerchandiseBindUpdate(string BindID,string BindName, int MerchandiseUnitID, decimal SellPrice)
        {
            string strUSP = "USP_MerchandiseBind_Update";
            try
            {
                SqlParameter[] parameters ={
                                            new SqlParameter("@BindID",SqlDbType.VarChar,9),
                                            new SqlParameter("@BindName",SqlDbType.VarChar,255),
                                            new SqlParameter("@MerchandiseUnitID",SqlDbType.Int),
                                            new SqlParameter("@SellPrice",SqlDbType.Decimal)
                                        };
                parameters[0].Value = BindID;
                parameters[1].Value = BindName;
                parameters[2].Value = MerchandiseUnitID;
                parameters[3].Value = SellPrice;

                return DbHelper.ExecuteNonQuerySQL(strUSP, CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                log.Write(string.Format("USP:{0}\r\nError:{1}", strUSP, ex.Message));
                throw;
            }
        }
    }
}
